package com.jg.visitor.common.bean;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
public class ResponseBean {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("数据")
    private Object data;
    @ApiModelProperty("正常响应消息")
    private String msg;
    @ApiModelProperty("错误响应消息")
    private String errorMsg;
    @ApiModelProperty("是否成功")
    private Boolean success;


    public static ResponseBean success(){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(ServiceCode.OK.getValue());
        responseBean.setMsg(ServiceCode.OK.getMsg());
        responseBean.setData(null);
        responseBean.setSuccess(true);

        return responseBean;
    }

    public static ResponseBean success(Object data){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(ServiceCode.OK.getValue());
        responseBean.setMsg(ServiceCode.OK.getMsg());
        responseBean.setData(data);
        responseBean.setSuccess(true);

        return responseBean;
    }

    public static ResponseBean error(Integer code,String msg){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code);
        responseBean.setErrorMsg(msg);
        responseBean.setSuccess(false);
        return responseBean;
    }

    public static ResponseBean error(ServiceCode code){
        return error(code,null);
    }

    public static ResponseBean error(ServiceCode code,Object data){
        ResponseBean responseBean = new ResponseBean();
        responseBean.setCode(code.getValue());
        responseBean.setMsg(code.getMsg());
        responseBean.setData(data);
        responseBean.setSuccess(false);

        return responseBean;
    }

}
